home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 101-125 / disk_114 / cdecl / cdgram.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  22KB  |  857 lines

  1.  
  2. # line 2 "cdgram.y"
  3. #include <stdio.h>
  4.  
  5. #define    MB_SHORT    0001
  6. #define    MB_LONG        0002
  7. #define    MB_UNSIGNED    0004
  8. #define MB_INT        0010
  9. #define MB_CHAR        0020
  10. #define MB_FLOAT    0040
  11. #define MB_DOUBLE    0100
  12.  
  13. int modbits = 0;
  14. int arbdims = 1;
  15. char *savedtype;
  16. char *savedname;
  17. char *ds(), *cat();
  18. char *index(), *malloc();
  19. char prev;
  20.  
  21. # line 21 "cdgram.y"
  22. typedef union  {
  23.     char *dynstr;
  24.     struct {
  25.         char *left;
  26.         char *right;
  27.     } halves;
  28. } YYSTYPE;
  29. # define DECLARE 257
  30. # define CAST 258
  31. # define INTO 259
  32. # define AS 260
  33. # define HELP 261
  34. # define EXPLAIN 262
  35. # define FUNCTION 263
  36. # define RETURNING 264
  37. # define POINTER 265
  38. # define TO 266
  39. # define ARRAY 267
  40. # define OF 268
  41. # define NAME 269
  42. # define NUMBER 270
  43. # define STRUCTUNION 271
  44. # define UNSIGNED 272
  45. # define LONG 273
  46. # define SHORT 274
  47. # define INT 275
  48. # define CHAR 276
  49. # define FLOAT 277
  50. # define DOUBLE 278
  51. #define yyclearin yychar = -1
  52. #define yyerrok yyerrflag = 0
  53. extern int yychar;
  54. extern int yyerrflag;
  55. #ifndef YYMAXDEPTH
  56. #define YYMAXDEPTH 150
  57. #endif
  58. YYSTYPE yylval, yyval;
  59. typedef int yytabelem;
  60. # define YYERRCODE 256
  61.  
  62. # line 219 "cdgram.y"
  63.  
  64. #include "cdlex.c"
  65.  
  66. #define LORS    (MB_LONG|MB_SHORT)
  67. #define UORL    (MB_UNSIGNED|MB_LONG)
  68. #define UORS    (MB_UNSIGNED|MB_SHORT)
  69. #define CORL    (MB_CHAR|MB_LONG)
  70. #define CORS    (MB_CHAR|MB_SHORT)
  71. #define CORU    (MB_CHAR|MB_UNSIGNED)
  72.  
  73. mbcheck()
  74. {
  75.     if ((modbits&LORS) == LORS)
  76.         unsupp("conflicting 'short' and 'long'");
  77.     if ((modbits&UORL) == UORL)
  78.         unport("unsigned with long");
  79.     if ((modbits&UORS) == UORS)
  80.         unport("unsigned with short");
  81.     if ((modbits&CORL) == CORL)
  82.         unsupp("long char");
  83.     if ((modbits&CORS) == CORS)
  84.         unsupp("short char");
  85.     if ((modbits&CORU) == CORU)
  86.         unport("unsigned char");
  87. }
  88.  
  89. savetype(s)
  90. char *s;
  91. {
  92.     savedtype = s;
  93. }
  94.  
  95. savename(s)
  96. char *s;
  97. {
  98.     savedname = s;
  99. }
  100. yytabelem yyexca[] ={
  101. -1, 1,
  102.     0, -1,
  103.     -2, 0,
  104.     };
  105. # define YYNPROD 39
  106. # define YYLAST 278
  107. yytabelem yyact[]={
  108.  
  109.     25,    31,    32,    33,    27,    28,    29,    30,    31,    32,
  110.     33,    27,    28,    29,    30,    57,    20,    53,    19,    35,
  111.     61,    37,    48,    36,    11,     7,    10,    62,    54,    51,
  112.     67,    15,    16,    64,    41,    34,    65,    59,    56,    26,
  113.     24,    17,    55,    49,    40,    14,     9,    38,    13,     2,
  114.      1,    22,    39,    52,    12,    42,    18,    23,     0,     0,
  115.      0,    44,    45,    47,    46,     0,     0,     0,     0,     0,
  116.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  117.      0,     0,     0,     0,     0,    43,    60,     0,     0,     0,
  118.     63,     0,     0,     0,     0,     0,     0,     0,    66,     0,
  119.      0,     0,     0,    68,     0,     0,     0,     0,     0,     0,
  120.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  121.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  122.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  123.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  124.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  125.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  126.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  127.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  128.      0,     0,    58,     0,     0,     0,     0,     0,     0,     0,
  129.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  130.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  131.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  132.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  133.      0,     0,     0,     0,     0,    21,     0,     0,     0,     0,
  134.      0,     0,     0,    50,     0,     0,     0,     0,     0,     0,
  135.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  136.      0,     8,     4,     5,     0,     0,     3,     6 };
  137. yytabelem yypact[]={
  138.  
  139.  -1000,    15, -1000,    36,  -243,  -245, -1000, -1000,    35, -1000,
  140.   -229,  -227,   -24,  -271, -1000,  -244,  -244,    34,    -6,   -24,
  141.    -24, -1000, -1000,  -264, -1000,  -247, -1000, -1000, -1000, -1000,
  142.  -1000, -1000, -1000, -1000,    33,   -11,  -253,  -238, -1000,    32,
  143.  -1000,    -3, -1000,   -78, -1000,    -4, -1000, -1000, -1000, -1000,
  144.   -244,  -249,  -241, -1000,  -244, -1000, -1000, -1000,   -60, -1000,
  145.  -1000,    -5,  -244, -1000, -1000,  -234, -1000,  -244, -1000 };
  146. yytabelem yypgo[]={
  147.  
  148.      0,    57,    40,    47,    39,    41,    56,    55,    53,    51,
  149.     35,    50,    49,    48 };
  150. yytabelem yyr1[]={
  151.  
  152.      0,    11,    11,    12,    12,    12,    12,    12,    12,     5,
  153.      5,     6,     6,     6,     6,     7,     7,    10,    10,    10,
  154.     10,    10,     8,     8,     3,    13,     9,     9,     9,     9,
  155.      2,     2,     2,     2,     1,     1,     4,     4,     4 };
  156. yytabelem yyr2[]={
  157.  
  158.      0,     0,     4,     5,    11,    11,     9,     2,     5,     2,
  159.      5,     7,     5,     7,     3,     5,     7,     7,    13,     9,
  160.      7,     3,     1,     3,     5,     1,     3,     3,     5,     5,
  161.      3,     3,     3,     3,     3,     5,     3,     3,     3 };
  162. yytabelem yychk[]={
  163.  
  164.  -1000,   -11,   -12,   261,   257,   258,   262,    10,   256,    10,
  165.    269,   269,    -3,   -13,    10,   260,   259,    -5,    -6,    42,
  166.     40,   269,    -9,    -1,    -2,   271,    -4,   275,   276,   277,
  167.    278,   272,   273,   274,   -10,   263,   267,   265,    -3,   -10,
  168.     10,    40,    -7,    91,    -5,    -5,    -2,    -4,   269,    10,
  169.    264,    40,    -8,   270,   266,    10,    41,    93,   270,    41,
  170.    -10,   269,   268,   -10,    93,    41,   -10,   264,   -10 };
  171. yytabelem yydef[]={
  172.  
  173.      1,    -2,     2,     0,     0,     0,    25,     7,     0,     3,
  174.      0,     0,     0,     0,     8,    25,    25,     0,     9,     0,
  175.      0,    14,    24,    26,    27,     0,    34,    30,    31,    32,
  176.     33,    36,    37,    38,     0,     0,    22,     0,    21,     0,
  177.      6,     0,    12,     0,    10,     0,    28,    35,    29,     4,
  178.     25,     0,     0,    23,    25,     5,    11,    15,     0,    13,
  179.     17,     0,    25,    20,    16,     0,    19,    25,    18 };
  180. typedef struct { char *t_name; int t_val; } yytoktype;
  181. #ifndef YYDEBUG
  182. #    define YYDEBUG    0    /* don't allow debugging */
  183. #endif
  184.  
  185. #if YYDEBUG
  186.  
  187. yytoktype yytoks[] =
  188. {
  189.     "DECLARE",    257,
  190.     "CAST",    258,
  191.     "INTO",    259,
  192.     "AS",    260,
  193.     "HELP",    261,
  194.     "EXPLAIN",    262,
  195.     "FUNCTION",    263,
  196.     "RETURNING",    264,
  197.     "POINTER",    265,
  198.     "TO",    266,
  199.     "ARRAY",    267,
  200.     "OF",    268,
  201.     "NAME",    269,
  202.     "NUMBER",    270,
  203.     "STRUCTUNION",    271,
  204.     "UNSIGNED",    272,
  205.     "LONG",    273,
  206.     "SHORT",    274,
  207.     "INT",    275,
  208.     "CHAR",    276,
  209.     "FLOAT",    277,
  210.     "DOUBLE",    278,
  211.     "-unknown-",    -1    /* ends search */
  212. };
  213.  
  214. char * yyreds[] =
  215. {
  216.     "-no such reduction-",
  217.     "prog : /* empty */",
  218.     "prog : prog stat",
  219.     "stat : HELP '\n'",
  220.     "stat : DECLARE NAME AS adecl '\n'",
  221.     "stat : CAST NAME INTO adecl '\n'",
  222.     "stat : EXPLAIN type cdecl '\n'",
  223.     "stat : '\n'",
  224.     "stat : error '\n'",
  225.     "cdecl : cdecl1",
  226.     "cdecl : '*' cdecl",
  227.     "cdecl1 : cdecl1 '(' ')'",
  228.     "cdecl1 : cdecl1 cdims",
  229.     "cdecl1 : '(' cdecl ')'",
  230.     "cdecl1 : NAME",
  231.     "cdims : '[' ']'",
  232.     "cdims : '[' NUMBER ']'",
  233.     "adecl : FUNCTION RETURNING adecl",
  234.     "adecl : FUNCTION '(' NAME ')' RETURNING adecl",
  235.     "adecl : ARRAY adims OF adecl",
  236.     "adecl : POINTER TO adecl",
  237.     "adecl : type",
  238.     "adims : /* empty */",
  239.     "adims : NUMBER",
  240.     "type : tinit c_type",
  241.     "tinit : /* empty */",
  242.     "c_type : mod_list",
  243.     "c_type : tname",
  244.     "c_type : mod_list tname",
  245.     "c_type : STRUCTUNION NAME",
  246.     "tname : INT",
  247.     "tname : CHAR",
  248.     "tname : FLOAT",
  249.     "tname : DOUBLE",
  250.     "mod_list : modifier",
  251.     "mod_list : mod_list modifier",
  252.     "modifier : UNSIGNED",
  253.     "modifier : LONG",
  254.     "modifier : SHORT",
  255. };
  256. #endif /* YYDEBUG */
  257. /* #ident    "@(#)yacc:yaccpar    1.10" */
  258.  
  259. /*
  260. ** Skeleton parser driver for yacc output
  261. */
  262.  
  263. /*
  264. ** yacc user known macros and defines
  265. */
  266. #define YYERROR        goto yyerrlab
  267. #define YYACCEPT    return(0)
  268. #define YYABORT        return(1)
  269. #define YYBACKUP( newtoken, newvalue )\
  270. {\
  271.     if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
  272.     {\
  273.         yyerror( "syntax error - cannot backup" );\
  274.         goto yyerrlab;\
  275.     }\
  276.     yychar = newtoken;\
  277.     yystate = *yyps;\
  278.     yylval = newvalue;\
  279.     goto yynewstate;\
  280. }
  281. #define YYRECOVERING()    (!!yyerrflag)
  282. #ifndef YYDEBUG
  283. #    define YYDEBUG    1    /* make debugging available */
  284. #endif
  285.  
  286. /*
  287. ** user known globals
  288. */
  289. int yydebug;            /* set to 1 to get debugging */
  290.  
  291. /*
  292. ** driver internal defines
  293. */
  294. #define YYFLAG        (-1000)
  295.  
  296. /*
  297. ** global variables used by the parser
  298. */
  299. YYSTYPE yyv[ YYMAXDEPTH ];    /* value stack */
  300. int yys[ YYMAXDEPTH ];        /* state stack */
  301.  
  302. YYSTYPE *yypv;            /* top of value stack */
  303. int *yyps;            /* top of state stack */
  304.  
  305. int yystate;            /* current state */
  306. int yytmp;            /* extra var (lasts between blocks) */
  307.  
  308. int yynerrs;            /* number of errors */
  309. int yyerrflag;            /* error recovery flag */
  310. int yychar;            /* current input token number */
  311.  
  312.  
  313.  
  314. /*
  315. ** yyparse - return 0 if worked, 1 if syntax error not recovered from
  316. */
  317. int
  318. yyparse()
  319. {
  320.     register YYSTYPE *yypvt;    /* top of value stack for $vars */
  321.  
  322.     /*
  323.     ** Initialize externals - yyparse may be called more than once
  324.     */
  325.     yypv = &yyv[-1];
  326.     yyps = &yys[-1];
  327.     yystate = 0;
  328.     yytmp = 0;
  329.     yynerrs = 0;
  330.     yyerrflag = 0;
  331.     yychar = -1;
  332.  
  333.     goto yystack;
  334.     {
  335.         register YYSTYPE *yy_pv;    /* top of value stack */
  336.         register int *yy_ps;        /* top of state stack */
  337.         register int yy_state;        /* current state */
  338.         register int  yy_n;        /* internal state number info */
  339.  
  340.         /*
  341.         ** get globals into registers.
  342.         ** branch to here only if YYBACKUP was called.
  343.         */
  344.     yynewstate:
  345.         yy_pv = yypv;
  346.         yy_ps = yyps;
  347.         yy_state = yystate;
  348.         goto yy_newstate;
  349.  
  350.         /*
  351.         ** get globals into registers.
  352.         ** either we just started, or we just finished a reduction
  353.         */
  354.     yystack:
  355.         yy_pv = yypv;
  356.         yy_ps = yyps;
  357.         yy_state = yystate;
  358.  
  359.         /*
  360.         ** top of for (;;) loop while no reductions done
  361.         */
  362.     yy_stack:
  363.         /*
  364.         ** put a state and value onto the stacks
  365.         */
  366. #if YYDEBUG
  367.         /*
  368.         ** if debugging, look up token value in list of value vs.
  369.         ** name pairs.  0 and negative (-1) are special values.
  370.         ** Note: linear search is used since time is not a real
  371.         ** consideration while debugging.
  372.         */
  373.         if ( yydebug )
  374.         {
  375.             register int yy_i;
  376.  
  377.             printf( "State %d, token ", yy_state );
  378.             if ( yychar == 0 )
  379.                 printf( "end-of-file\n" );
  380.             else if ( yychar < 0 )
  381.                 printf( "-none-\n" );
  382.             else
  383.             {
  384.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  385.                     yy_i++ )
  386.                 {
  387.                     if ( yytoks[yy_i].t_val == yychar )
  388.                         break;
  389.                 }
  390.                 printf( "%s\n", yytoks[yy_i].t_name );
  391.             }
  392.         }
  393. #endif /* YYDEBUG */
  394.         if ( ++yy_ps >= &yys[ YYMAXDEPTH ] )    /* room on stack? */
  395.         {
  396.             yyerror( "yacc stack overflow" );
  397.             YYABORT;
  398.         }
  399.         *yy_ps = yy_state;
  400.         *++yy_pv = yyval;
  401.  
  402.         /*
  403.         ** we have a new state - find out what to do
  404.         */
  405.     yy_newstate:
  406.         if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
  407.             goto yydefault;        /* simple state */
  408. #if YYDEBUG
  409.         /*
  410.         ** if debugging, need to mark whether new token grabbed
  411.         */
  412.         yytmp = yychar < 0;
  413. #endif
  414.         if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  415.             yychar = 0;        /* reached EOF */
  416. #if YYDEBUG
  417.         if ( yydebug && yytmp )
  418.         {
  419.             register int yy_i;
  420.  
  421.             printf( "Received token " );
  422.             if ( yychar == 0 )
  423.                 printf( "end-of-file\n" );
  424.             else if ( yychar < 0 )
  425.                 printf( "-none-\n" );
  426.             else
  427.             {
  428.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  429.                     yy_i++ )
  430.                 {
  431.                     if ( yytoks[yy_i].t_val == yychar )
  432.                         break;
  433.                 }
  434.                 printf( "%s\n", yytoks[yy_i].t_name );
  435.             }
  436.         }
  437. #endif /* YYDEBUG */
  438.         if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
  439.             goto yydefault;
  440.         if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar )    /*valid shift*/
  441.         {
  442.             yychar = -1;
  443.             yyval = yylval;
  444.             yy_state = yy_n;
  445.             if ( yyerrflag > 0 )
  446.                 yyerrflag--;
  447.             goto yy_stack;
  448.         }
  449.  
  450.     yydefault:
  451.         if ( ( yy_n = yydef[ yy_state ] ) == -2 )
  452.         {
  453. #if YYDEBUG
  454.             yytmp = yychar < 0;
  455. #endif
  456.             if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  457.                 yychar = 0;        /* reached EOF */
  458. #if YYDEBUG
  459.             if ( yydebug && yytmp )
  460.             {
  461.                 register int yy_i;
  462.  
  463.                 printf( "Received token " );
  464.                 if ( yychar == 0 )
  465.                     printf( "end-of-file\n" );
  466.                 else if ( yychar < 0 )
  467.                     printf( "-none-\n" );
  468.                 else
  469.                 {
  470.                     for ( yy_i = 0;
  471.                         yytoks[yy_i].t_val >= 0;
  472.                         yy_i++ )
  473.                     {
  474.                         if ( yytoks[yy_i].t_val
  475.                             == yychar )
  476.                         {
  477.                             break;
  478.                         }
  479.                     }
  480.                     printf( "%s\n", yytoks[yy_i].t_name );
  481.                 }
  482.             }
  483. #endif /* YYDEBUG */
  484.             /*
  485.             ** look through exception table
  486.             */
  487.             {
  488.                 register int *yyxi = yyexca;
  489.  
  490.                 while ( ( *yyxi != -1 ) ||
  491.                     ( yyxi[1] != yy_state ) )
  492.                 {
  493.                     yyxi += 2;
  494.                 }
  495.                 while ( ( *(yyxi += 2) >= 0 ) &&
  496.                     ( *yyxi != yychar ) )
  497.                     ;
  498.                 if ( ( yy_n = yyxi[1] ) < 0 )
  499.                     YYACCEPT;
  500.             }
  501.         }
  502.  
  503.         /*
  504.         ** check for syntax error
  505.         */
  506.         if ( yy_n == 0 )    /* have an error */
  507.         {
  508.             /* no worry about speed here! */
  509.             switch ( yyerrflag )
  510.             {
  511.             case 0:        /* new error */
  512.                 yyerror( "syntax error" );
  513.                 goto skip_init;
  514.             yyerrlab:
  515.                 /*
  516.                 ** get globals into registers.
  517.                 ** we have a user generated syntax type error
  518.                 */
  519.                 yy_pv = yypv;
  520.                 yy_ps = yyps;
  521.                 yy_state = yystate;
  522.                 yynerrs++;
  523.             skip_init:
  524.             case 1:
  525.             case 2:        /* incompletely recovered error */
  526.                     /* try again... */
  527.                 yyerrflag = 3;
  528.                 /*
  529.                 ** find state where "error" is a legal
  530.                 ** shift action
  531.                 */
  532.                 while ( yy_ps >= yys )
  533.                 {
  534.                     yy_n = yypact[ *yy_ps ] + YYERRCODE;
  535.                     if ( yy_n >= 0 && yy_n < YYLAST &&
  536.                         yychk[yyact[yy_n]] == YYERRCODE)                    {
  537.                         /*
  538.                         ** simulate shift of "error"
  539.                         */
  540.                         yy_state = yyact[ yy_n ];
  541.                         goto yy_stack;
  542.                     }
  543.                     /*
  544.                     ** current state has no shift on
  545.                     ** "error", pop stack
  546.                     */
  547. #if YYDEBUG
  548. #    define _POP_ "Error recovery pops state %d, uncovers state %d\n"
  549.                     if ( yydebug )
  550.                         printf( _POP_, *yy_ps,
  551.                             yy_ps[-1] );
  552. #    undef _POP_
  553. #endif
  554.                     yy_ps--;
  555.                     yy_pv--;
  556.                 }
  557.                 /*
  558.                 ** there is no state on stack with "error" as
  559.                 ** a valid shift.  give up.
  560.                 */
  561.                 YYABORT;
  562.             case 3:        /* no shift yet; eat a token */
  563. #if YYDEBUG
  564.                 /*
  565.                 ** if debugging, look up token in list of
  566.                 ** pairs.  0 and negative shouldn't occur,
  567.                 ** but since timing doesn't matter when
  568.                 ** debugging, it doesn't hurt to leave the
  569.                 ** tests here.
  570.                 */
  571.                 if ( yydebug )
  572.                 {
  573.                     register int yy_i;
  574.  
  575.                     printf( "Error recovery discards " );
  576.                     if ( yychar == 0 )
  577.                         printf( "token end-of-file\n" );
  578.                     else if ( yychar < 0 )
  579.                         printf( "token -none-\n" );
  580.                     else
  581.                     {
  582.                         for ( yy_i = 0;
  583.                             yytoks[yy_i].t_val >= 0;
  584.                             yy_i++ )
  585.                         {
  586.                             if ( yytoks[yy_i].t_val
  587.                                 == yychar )
  588.                             {
  589.                                 break;
  590.                             }
  591.                         }
  592.                         printf( "token %s\n",
  593.                             yytoks[yy_i].t_name );
  594.                     }
  595.                 }
  596. #endif /* YYDEBUG */
  597.                 if ( yychar == 0 )    /* reached EOF. quit */
  598.                     YYABORT;
  599.                 yychar = -1;
  600.                 goto yy_newstate;
  601.             }
  602.         }/* end if ( yy_n == 0 ) */
  603.         /*
  604.         ** reduction by production yy_n
  605.         ** put stack tops, etc. so things right after switch
  606.         */
  607. #if YYDEBUG
  608.         /*
  609.         ** if debugging, print the string that is the user's
  610.         ** specification of the reduction which is just about
  611.         ** to be done.
  612.         */
  613.         if ( yydebug )
  614.             printf( "Reduce by (%d) \"%s\"\n",
  615.                 yy_n, yyreds[ yy_n ] );
  616. #endif
  617.         yytmp = yy_n;            /* value to switch over */
  618.         yypvt = yy_pv;            /* $vars top of value stack */
  619.         /*
  620.         ** Look in goto table for next state
  621.         ** Sorry about using yy_state here as temporary
  622.         ** register variable, but why not, if it works...
  623.         ** If yyr2[ yy_n ] doesn't have the low order bit
  624.         ** set, then there is no action to be done for
  625.         ** this reduction.  So, no saving & unsaving of
  626.         ** registers done.  The only difference between the
  627.         ** code just after the if and the body of the if is
  628.         ** the goto yy_stack in the body.  This way the test
  629.         ** can be made before the choice of what to do is needed.
  630.         */
  631.         {
  632.             /* length of production doubled with extra bit */
  633.             register int yy_len = yyr2[ yy_n ];
  634.  
  635.             if ( !( yy_len & 01 ) )
  636.             {
  637.                 yy_len >>= 1;
  638.                 yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  639.                 yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  640.                     *( yy_ps -= yy_len ) + 1;
  641.                 if ( yy_state >= YYLAST ||
  642.                     yychk[ yy_state =
  643.                     yyact[ yy_state ] ] != -yy_n )
  644.                 {
  645.                     yy_state = yyact[ yypgo[ yy_n ] ];
  646.                 }
  647.                 goto yy_stack;
  648.             }
  649.             yy_len >>= 1;
  650.             yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  651.             yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  652.                 *( yy_ps -= yy_len ) + 1;
  653.             if ( yy_state >= YYLAST ||
  654.                 yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
  655.             {
  656.                 yy_state = yyact[ yypgo[ yy_n ] ];
  657.             }
  658.         }
  659.                     /* save until reenter driver code */
  660.         yystate = yy_state;
  661.         yyps = yy_ps;
  662.         yypv = yy_pv;
  663.     }
  664.     /*
  665.     ** code supplied by user is placed in this switch
  666.     */
  667.     switch( yytmp )
  668.     {
  669.         
  670. case 3:
  671. # line 45 "cdgram.y"
  672. {
  673.             help();
  674.             } break;
  675. case 4:
  676. # line 49 "cdgram.y"
  677. {
  678.             printf("%s %s%s%s",savedtype,yypvt[-1].halves.left,yypvt[-3].dynstr,yypvt[-1].halves.right);
  679. #ifdef MKPROGRAM
  680.             if (prev == 'f')
  681.                 printf("\n{\n}\n");
  682.             else
  683.                 printf(";\n");
  684. #else
  685.             printf("\n");
  686. #endif
  687.             free(yypvt[-1].halves.left);
  688.             free(yypvt[-1].halves.right);
  689.             free(yypvt[-3].dynstr);
  690.             } break;
  691. case 5:
  692. # line 64 "cdgram.y"
  693. {
  694.             if (prev == 'f')
  695.                 unsupp("Cast into function");
  696.             else if (prev=='A' || prev=='a')
  697.                 unsupp("Cast into array");
  698.             printf("(%s",savedtype);
  699.             if (strlen(yypvt[-1].halves.left)+strlen(yypvt[-1].halves.right))
  700.                 printf(" %s%s",yypvt[-1].halves.left,yypvt[-1].halves.right);
  701.             printf(")%s\n",yypvt[-3].dynstr);
  702.             free(yypvt[-1].halves.left);
  703.             free(yypvt[-1].halves.right);
  704.             free(yypvt[-3].dynstr);
  705.             } break;
  706. case 6:
  707. # line 78 "cdgram.y"
  708. { printf("declare %s as %s%s\n",savedname,yypvt[-1].dynstr,yypvt[-2].dynstr); } break;
  709. case 8:
  710. # line 81 "cdgram.y"
  711. {
  712.             yyerrok;
  713.             } break;
  714. case 10:
  715. # line 88 "cdgram.y"
  716. { yyval.dynstr = cat(yypvt[-0].dynstr,ds("pointer to "),NULL); } break;
  717. case 11:
  718. # line 92 "cdgram.y"
  719. { yyval.dynstr = cat(yypvt[-2].dynstr,ds("function returning "),NULL); } break;
  720. case 12:
  721. # line 94 "cdgram.y"
  722. { yyval.dynstr = cat(yypvt[-1].dynstr,ds("array "),yypvt[-0].dynstr); } break;
  723. case 13:
  724. # line 96 "cdgram.y"
  725. { yyval.dynstr = yypvt[-1].dynstr; } break;
  726. case 14:
  727. # line 98 "cdgram.y"
  728. {
  729.                 savename(yypvt[-0].dynstr);
  730.                 yyval.dynstr = ds("");
  731.             } break;
  732. case 15:
  733. # line 105 "cdgram.y"
  734. { yyval.dynstr = ds("of "); } break;
  735. case 16:
  736. # line 107 "cdgram.y"
  737. { yyval.dynstr = cat(yypvt[-1].dynstr,ds(" of "),NULL); } break;
  738. case 17:
  739. # line 111 "cdgram.y"
  740. {
  741.             if (prev == 'f')
  742.                 unsupp("Function returning function");
  743.             else if (prev=='A' || prev=='a')
  744.                 unsupp("Function returning array");
  745.             yyval.halves.left = yypvt[-0].halves.left;
  746.             yyval.halves.right = cat(ds("()"),yypvt[-0].halves.right,NULL);
  747.             prev = 'f';
  748.             } break;
  749. case 18:
  750. # line 121 "cdgram.y"
  751. {
  752.             if (prev == 'f')
  753.                 unsupp("Function returning function");
  754.             else if (prev=='A' || prev=='a')
  755.                 unsupp("Function returning array");
  756.             yyval.halves.left = yypvt[-0].halves.left;
  757.             yyval.halves.right = cat(ds("("),yypvt[-3].dynstr,ds(")"));
  758.             yyval.halves.right = cat(yyval.halves.right,yypvt[-0].halves.right,NULL);
  759.             prev = 'f';
  760.             } break;
  761. case 19:
  762. # line 132 "cdgram.y"
  763. {
  764.             if (prev == 'f')
  765.                 unsupp("Array of function");
  766.             else if (prev == 'a')
  767.                 unsupp("Inner array of unspecified size");
  768.             if (arbdims)
  769.                 prev = 'a';
  770.             else
  771.                 prev = 'A';
  772.             yyval.halves.left = yypvt[-0].halves.left;
  773.             yyval.halves.right = cat(yypvt[-2].dynstr,yypvt[-0].halves.right,NULL);
  774.             } break;
  775. case 20:
  776. # line 145 "cdgram.y"
  777. {
  778.             if (prev == 'a')
  779.                 unsupp("Pointer to array of unspecified dimension");
  780.             if (prev=='a' || prev=='A' || prev=='f') {
  781.                 yyval.halves.left = cat(yypvt[-0].halves.left,ds("(*"),NULL);
  782.                 yyval.halves.right = cat(ds(")"),yypvt[-0].halves.right,NULL);
  783.             } else {
  784.                 yyval.halves.left = cat(yypvt[-0].halves.left,ds("*"),NULL);
  785.                 yyval.halves.right = yypvt[-0].halves.right;
  786.             }
  787.             prev = 'p';
  788.             } break;
  789. case 21:
  790. # line 158 "cdgram.y"
  791. {
  792.             savetype(yypvt[-0].dynstr);
  793.             yyval.halves.left = ds("");
  794.             yyval.halves.right = ds("");
  795.             prev = 't';
  796.             } break;
  797. case 22:
  798. # line 167 "cdgram.y"
  799. {
  800.             arbdims = 1;
  801.             yyval.dynstr = ds("[]");
  802.             } break;
  803. case 23:
  804. # line 172 "cdgram.y"
  805. {
  806.             arbdims = 0;
  807.             yyval.dynstr = cat(ds("["),yypvt[-0].dynstr,ds("]"));
  808.             } break;
  809. case 24:
  810. # line 179 "cdgram.y"
  811. { mbcheck(); yyval.dynstr = yypvt[-0].dynstr; } break;
  812. case 25:
  813. # line 183 "cdgram.y"
  814. { modbits = 0; } break;
  815. case 26:
  816. # line 187 "cdgram.y"
  817. { yyval.dynstr = yypvt[-0].dynstr; } break;
  818. case 27:
  819. # line 189 "cdgram.y"
  820. { yyval.dynstr = yypvt[-0].dynstr; } break;
  821. case 28:
  822. # line 191 "cdgram.y"
  823. { yyval.dynstr = cat(yypvt[-1].dynstr,ds(" "),yypvt[-0].dynstr); } break;
  824. case 29:
  825. # line 193 "cdgram.y"
  826. { yyval.dynstr = cat(yypvt[-1].dynstr,ds(" "),yypvt[-0].dynstr); } break;
  827. case 30:
  828. # line 197 "cdgram.y"
  829. { modbits |= MB_INT; yyval.dynstr = yypvt[-0].dynstr; } break;
  830. case 31:
  831. # line 199 "cdgram.y"
  832. { modbits |= MB_CHAR; yyval.dynstr = yypvt[-0].dynstr; } break;
  833. case 32:
  834. # line 201 "cdgram.y"
  835. { modbits |= MB_FLOAT; yyval.dynstr = yypvt[-0].dynstr; } break;
  836. case 33:
  837. # line 203 "cdgram.y"
  838. { modbits |= MB_DOUBLE; yyval.dynstr = yypvt[-0].dynstr; } break;
  839. case 34:
  840. # line 207 "cdgram.y"
  841. { yyval.dynstr = yypvt[-0].dynstr; } break;
  842. case 35:
  843. # line 209 "cdgram.y"
  844. { yyval.dynstr = cat(yypvt[-1].dynstr,ds(" "),yypvt[-0].dynstr); } break;
  845. case 36:
  846. # line 213 "cdgram.y"
  847. { modbits |= MB_UNSIGNED; yyval.dynstr = yypvt[-0].dynstr; } break;
  848. case 37:
  849. # line 215 "cdgram.y"
  850. { modbits |= MB_LONG; yyval.dynstr = yypvt[-0].dynstr; } break;
  851. case 38:
  852. # line 217 "cdgram.y"
  853. { modbits |= MB_SHORT; yyval.dynstr = yypvt[-0].dynstr; } break;
  854.     }
  855.     goto yystack;        /* reset registers in driver code */
  856. }
  857.